﻿#include <iostream>
#include "myJsonCpp.h"



void test1()
{
	std::cout << "------------------------test1------------------------" << std::endl;

	//构造函数
	Json v1;
	Json v2 = true;
	Json v3 = 10;
	Json v4 = 3.14;
	Json v5 = "hello";
	Json v6 = v5;


	//运算符重载
	bool b = v2;
	int i = v3;
	double d = v4;
	const std::string& str = v5;
	std::cout << "b = " << b << std::endl;
	std::cout << "i = " << i << std::endl;
	std::cout << "d = " << d << std::endl;
	std::cout << "str = " << str << std::endl;
}

void test2()
{
	std::cout << "------------------------test2------------------------" << std::endl;
	//测试Json数组
	Json arr;
	arr[0] = true;
	arr[1] = 123;
	arr.Append(1.23);
	arr.Append("world");

	bool b = arr[0];
	int i = arr[1];
	double d = arr[2];
	const std::string& str = arr[3];
	
	std::cout << "b = " << b << std::endl;
	std::cout << "i = " << i << std::endl;
	std::cout << "d = " << d << std::endl;
	std::cout << "str = " << str << std::endl;
}

void test3()
{
	std::cout << "------------------------test3------------------------" << std::endl;

	//测试Json转string
	Json v1;
	Json v2 = true;
	Json v3 = 10;
	Json v4 = 3.14;
	Json v5 = "hello";
	Json v6 = v5;

	std::cout << v1.Str() << std::endl;
	std::cout << v2.Str() << std::endl;
	std::cout << v3.Str() << std::endl;
	std::cout << v4.Str() << std::endl;
	std::cout << v5.Str() << std::endl;
	std::cout << v6.Str() << std::endl;

	Json arr;
	arr[0] = true;
	arr[1] = 123;
	arr.Append(1.23);
	arr.Append("world");
	std::cout << arr.Str() << std::endl;
	for (Json::arrayIterator it = arr.Begin(); it != arr.End(); ++it)
	{
		std::cout << "it: " << it->Str() << std::endl;
	}

	std::cout << "arr.Has(0):" << arr.Has(0) << std::endl;
	std::cout << "arr.Has(4):" << arr.Has(4) << std::endl;
	arr.Remove(0);
	std::cout << arr.Str() << std::endl;
 
	Json obj;
	obj["bool"] = true;
	obj["int"] = 123;
	obj["double"] = 1.23;
	obj["str"] = "hello world";
	std::cout << obj.Str() << std::endl;

	std::cout << "obj.Has(0):" << obj.Has("bool") << std::endl;
	std::cout << "obj.Has(4):" << obj.Has("afasdf") << std::endl;
	obj.Remove("bool");
	std::cout << obj.Str() << std::endl;
}


int main(void)
{
	test1();
	test2();
	test3();

	return 0;
}